/**============================================================================
 *
 * Author: luo1o1o1o 
 *
 * QQ: 330240995, PHONE: 17600071321
 *
 * Last modified: 2021-06-09 09:52
 *
 * Filename: validate.js
 *
 * Description: json schema 校验
 *
 ============================================================================**/

const Ajv = require('ajv')
const ajv = new Ajv({
    allErrors: true, // 输出所有的错误
})

/**
 * @Author: luo1o1o1o
 * @QQ: 330240995, @PHONE: 17600071321
 * @Date: 2021-06-09 10:38
 * @desc: json schema 校验
 */
function validate(schema, data = {}) {
    const valid = ajv.validate(schema, data)
    if (!valid) {
        return ajv.errors[0]
    }
}

module.exports = validate
